package tech.konata.styleslite.event;

import net.minecraft.client.renderer.ShaderInstance;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceProvider;
import net.minecraft.server.packs.resources.SimpleResource;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import tech.konata.styleslite.rendering.shaders.CustomResourceProvider;
import tech.konata.styleslite.rendering.shaders.GlProgram;
import tech.konata.styleslite.rendering.shaders.Shaders;

import java.io.IOException;

public class ForgeEventsHandler {

    boolean shadersLoaded = false;

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onEvent(RenderGameOverlayEvent.Text.Pre event) {

        if (!shadersLoaded) {
            shadersLoaded = true;

            Shaders.initShaders();

            GlProgram.forEachProgram(
                    loader -> {
                        ShaderInstance shaderinstance = loader.getFirst().apply(CustomResourceProvider.INSTANCE);
                        loader.getSecond().accept(shaderinstance);
                    }
            );

        }

    }

}
